package com.sojoys.artifact.manager;

import com.sojoys.artifact.factory.remote.ActiveMQRemoteProxyFactory;
import com.sojoys.artifact.factory.remote.IRemoteProxyFactory;

/**
 * @author : DengYing
 * @CreateDate : 2017年8月14日 下午1:02:16
 * @Description ：Please describe this document
 */
public class RemoteProxyManager {
	
	private RemoteProxyManager() {
	}

	private static RemoteProxyManager ME = new RemoteProxyManager();

	public static RemoteProxyManager me() {
		return ME;
	}
	
	private IRemoteProxyFactory factory = new ActiveMQRemoteProxyFactory();

	public void setFactory(IRemoteProxyFactory factory) {
		this.factory = factory;
	}
	
//	public static IRemoteProxy getRemoteProxy(){
//		return defaultRemoteProxyFactory.getProxy();
//	}
	
	
//	public static <T> T create(final Class<?> interfaceClass) {
//		return create(interfaceClass, null);
//	}

	/**
	 * 创建一个接口
	 * 
	 * @param interfaceClass
	 * @param destination
	 */
	public <T> T create(final Class<?> interfaceClass, final String destination, final boolean topic){
		return this.factory.getProxy().create(interfaceClass, destination,topic);
	}

	/**
	 * 发送并接收
	 * 
	 * @param interfaceClass
	 * @return
	 */
	public <T> T createReceive(final Class<?> interfaceClass) {
		return createReceive(interfaceClass, null);
	}

	/**
	 * 发送并接收
	 * 
	 * @param interfaceClass
	 * @return
	 */
	public <T> T createReceive(final Class<?> interfaceClass, final String destination){
		return factory.getProxy().createReceive(interfaceClass, destination);
	}
}
